<template>
	<view style="margin-top: 180rpx;margin-left: 20rpx;margin-right: 20rpx;" v-if="user.frentLink!==5&&user!==''">
		<navbox title="用户信息"></navbox>
		<u--form labelPosition="left" :model="userInfo" ref="uForm" :rules="rules">
			<u-form-item label="名称" prop="nickName" borderBottom ref="item1">
				<u--input v-model="userInfo.nickName" border="none" disabled></u--input>
			</u-form-item>
			<u-form-item label="状态" prop="status" borderBottom @click="showSex = true; " ref="item1">
				<picker @change="bindPickerChange" :value="userInfo.status" :range="array">
					<view class="uni-input">{{array[index]}}</view>
				</picker>
			</u-form-item>
			<u-form-item label="角色" prop="frentLink" borderBottom @click="showSex = true;  " ref="item1">
				<picker @change="bindPickerChange2" :value="userInfo.frentLink" :range="array2">
					<view class="uni-input">{{array2[index2]}}</view>
				</picker>
			</u-form-item>
			<u-form-item label="备注" prop=" realName" borderBottom ref="item1">
				<u--textarea v-model="userInfo.realName" placeholder="请输入内容" count height="80"></u--textarea>
			</u-form-item>
			<u-form-item>
				<u-button text="渐变色按钮" @click="submit()"
					color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))">
				</u-button>
			</u-form-item>
		</u--form>
	</view>
</template>

<script>
	import navbox from '../components/navbox/navbox.vue'
	export default {
		data() {
			return {
				index2: 0,
				showSex: false,
				array: ['正常', '禁用'],
				array2: ['普通用户', '会员', '友链管理员', '会员、友链'],
				index: 0,
				userInfo: {
					id: "",
					nickName: '',
					status: '',
					frentLink: '',
					realName: ''
				},
				rules: {
				},
			}
		},
		onLoad(option) {
			this.userInfo.id = option.id
			this.userInfo.nickName = option.nickName
			this.userInfo.status = option.status
			this.userInfo.frentLink = option.frentLink
			this.userInfo.realName = option.realName
			this.index = option.status
			this.setIndex2(option.frentLink)
		},
		methods: {
			async submit() {
				console.log(this.userInfo)
				const res = await this.$myRuquest({
					url: '/wexinLogin/sgArticle/edi',
					method: "post",
					data: this.userInfo
				})
				if (res.data.data === true) {
					uni.switchTab({
	 
						url: '/pages/index/index'
					})
				}
				uni.showToast({
					title: res.data.data === true ? '修改成功' : '修改失败',
					icon: 'none'
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
				this.userInfo.status = this.index
			},
			bindPickerChange2: function(e) {
				console.log('picker发送选择改变，携带值为', e)
				this.index2 = e.detail.value
				this.setfrent(this.index2)
			},
			setIndex2(frentLink) {
				console.log(frentLink)
				if (frentLink === '5') {
					this.index2 = 0
				} else if (frentLink === '0') {
					this.index2 = 1
				} else if (frentLink === '3') {
					this.index2 = 2
				} else {
					this.index2 = 3
				}
			},
			setfrent(index) {
				if (index === '0') {
					this.userInfo.frentLink = 5
				} else if (index === '1') {
					this.userInfo.frentLink = 0
				} else if (index === '2') {
					this.userInfo.frentLink = 3
				} else {
					this.userInfo.frentLink = 30
				}
			}
		},
		components: {
			"navbox": navbox
		},
	}
</script>

<style>

</style>
